<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
String dept_id=String.valueOf(sessionMap.get("dept_id"));
%>
<html>
	<head>
		<title>部门材料库存</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=1',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					docSearch();
				}
			});

			$("#customer_id").combogrid({
				idField:"id",
				textField:"company",
				title:'选择客户',
				url: '<%=contextPath %>/springMVC/crm/listPageCustomer',
			    panelWidth:550,
			    panelHeight:400,
			    rownumbers:true,
			    fitColumns:true,
			    columns: [[  
			       {field:'id',title:'主键',hidden:true},  
			       {title:'客户类别',field:'type_name',width:200,align:'center'},
				   {title:'公司名称',field:'company',width:200,align:'center'},
				   {title:'联系人',field:'contact',width:200,align:'center'},
				   {title:'TEL',field:'tel',width:200,align:'center'}
			    ]],
			    toolbar:'#ctb',
			    pageSize:10,
			    pageList : [10,50,100],  
				pagination:true,
				onChange:function(){
					doSearch();
				}
			});
			
			$("#cSearchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 docSearch();
		       	} 
		   	}); 
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#material_type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=0',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			
			$('#table').datagrid({
				title:"客户库",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/warehouse/listPageBeforeDB?dept_id=<%=dept_id%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'客户id',field:'customer_id',hidden:true},
				    {title:'仓库id',field:'warehouse_id',hidden:true},
				    {title:'产品id',field:'product_id',hidden:true}
				]],
				columns:[[
					//{title:'部门',field:'dept_name',width:100,align:'center'},
					{title:'客户',field:'customer',width:100,align:'center'},
					{title:'分类',field:'material_type_name',width:80,align:'center'},
					{title:'材料编号',field:'code',width:80,align:'center'},
					{title:'材料名称',field:'name',width:100,align:'center'},
					{title:'规格型号',field:'format_type',width:100,align:'center'},
					{title:'计量单位',field:'unit_name',width:50,align:'center'},
					{title:'库存数量',field:'num',width:50,align:'center'},
					{title:'查看流水',field:'details',width:50,align:'center',formatter: function(value,row,index){
						return "<input type='button'  style='border:0px #ff0000 solid;width:25px;height:15px;cursor:pointer'class='icon-details'  onClick='showLog(\""+row.warehouse_id+"\",\""+row.product_id+"\",\""+row.customer_id+"\")'/>";
					}}
				]],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		
		function docSearch()
		{
			var cSearchValue = $('#cSearchValue').val();
			var type_id = $('#type_id').combotree('getValue');
			$('#customer_id').combogrid('clear');
			$('#customer_id').combogrid('grid').datagrid('load',{
				searchValue:cSearchValue,
				type_id:type_id
				});
		}
		
		function doSearch()
		{
			var customer_id = $("#customer_id").combogrid("getValue");
			var searchValue = $('#searchValue').val();
			var material_type_id = $('#material_type_id').combotree('getValue');
			$('#table').datagrid('load',				
				{
				customer_id:customer_id,
					searchValue:searchValue,
					material_type_id:material_type_id
				}
			);
		}
		function showLog(warehouse_id,product_id,customer_id){
			openDialogResize("<%=contextPath %>/springViews/warehouse/dbBeforeDetails.jsp?warehouse_id="+warehouse_id+"&product_id="+product_id+"&customer_id="+customer_id,1000, 800);
		}
		</script>
	<script type="text/javascript">
	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true,toolbar:'#tb'" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
				选择客户：<input  id="customer_id" name="customer_id" >
				分类：<input  id="material_type_id" name="material_type_id" class="easyui-combotree">
				材料编码/名称：<input id="searchValue" name="searchValue" style="width:150px" title="材料编码/名称" placeholder="材料编码/名称"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
		<div id="ctb" style="padding:3px;height:auto;">
			<div align="right">
				分类：<input  id="type_id" name="type_id" >
				查询条件：<input id="cSearchValue" name="cSearchValue"  title="客户名称或联系人" placeholder="客户名称/联系人"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="docSearch();"></a>
			</div>
		</div>
	</body>
</html>
